package com.xspace.android.xafcommon.adapter;

import android.view.View;
import android.view.ViewGroup;

import java.util.LinkedList;
import java.util.NoSuchElementException;

public abstract class BasePagerViewAdapter<T> extends BasePagerCanDeleteAdapter<T> {
	// 被移除view的堆栈
	protected LinkedList<View> viewStack = new LinkedList<View>();

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		super.destroyItem(container, position, object);
		viewStack.add((View) object);
	}

	public abstract View getView(int position, View convertView, ViewGroup parent);

	@Override
	protected View getView(ViewGroup container, int position) {
		View convertView = null;
		try {
			convertView = viewStack.removeFirst();
		} catch (NoSuchElementException e) {
		}
		convertView = getView(position, convertView, container);
		return convertView;
	}
}
